package org.androidpush.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.androidpush.R;
import org.androidpush.greendao.SelectCouInfo;

import java.util.List;

/**
 * Created by huang on 2017/4/16 0016.
 */
public class SelectCouAdpater extends BaseAdapter {

    private List<SelectCouInfo> datas;

    private LayoutInflater inflater;

    public SelectCouAdpater(Context context, List<SelectCouInfo> datas) {
        this.datas = datas;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder vHolder = null;
        SelectCouInfo courseDto = datas.get(position);

        if (convertView == null) {
            vHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.xml_selectcou_item, null);
            vHolder.tv_TeaCouId = (TextView) convertView.findViewById(R.id.id_selectcou_item_teacouId);

            vHolder.tv_CouName = (TextView) convertView
                    .findViewById(R.id.id_selectcou_item_couname);
            vHolder.tv_TeaName = (TextView) convertView
                    .findViewById(R.id.id_selectcou_item_teaname);
            vHolder.tv_Credit = (TextView) convertView
                    .findViewById(R.id.id_selectcou_item_credit);
            vHolder.tv_CouTime = (TextView) convertView
                    .findViewById(R.id.id_selectcou_item_time);
            vHolder.tv_CouNumb = (TextView) convertView
                    .findViewById(R.id.id_selectcou_item_numb);
            convertView.setTag(vHolder);
        }else {
            vHolder = (ViewHolder) convertView.getTag();
        }

        vHolder.tv_TeaCouId.setText(Long.toString(courseDto.getTeaCouId()));
        vHolder.tv_CouName.setText(courseDto.getCouName());
        vHolder.tv_TeaName.setText(courseDto.getTeaName());
        vHolder.tv_Credit.setText(courseDto.getCouCredit());
        vHolder.tv_CouTime.setText(courseDto.getTeaCouWeekTime()+","+Integer.toString(courseDto.getTeaCouStart()) + "-" + Integer.toString(courseDto.getTeaCouEnd()));
        vHolder.tv_CouNumb.setText(Integer.toString(courseDto.getTeaCouVolume()));
        return convertView;
    }

    class ViewHolder {
        TextView tv_TeaCouId,tv_CouName,tv_TeaName,tv_Credit,tv_CouTime,tv_CouNumb;
    }
}
